import { MUser } from '@/models/user';
import { useNavigate } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Button, Form, Input, message } from 'antd';
import styles from './index.less';
import {history} from "@@/core/history";
import {useEffect} from "react";

const LoginPage: React.FC = () => {
  const navigate = useNavigate();

    const local = JSON.parse(localStorage.getItem('auth') || 'null');
    useEffect(() => {
        if (!local) {
            history.push('/login');
        } else {
            history.push('/type');
            // history.push('/chart');
        }
    }, []);

  return (
    <div className={styles.container}>
      <img
        className={styles.logo}
        src={require('./assets/logo.png')}
        alt="源昀卓"
      />
      <Form
        className={styles.content}
        layout="vertical"
        onFinish={(values) => {
          if (values.username == 'admin' && values.password == 'admin123') {
            localStorage.setItem(
              'auth',
              JSON.stringify({
                username: values.username,
                password: values.password,
              }),
            );
              history.push('/type');
          } else {
            message.error('密码不正确');
          }
        }}
      >
        <h1 className={styles.title}>源昀卓管理平台</h1>
        {/*<div className={styles.desc}>*/}
        {/*  Smart park integrated management platform*/}
        {/*</div>*/}
        <Form.Item
          name="username"
          label="账号"
          rules={[{ required: true, whitespace: true, message: '请输入账号' }]}
        >
          <Input size="large" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, whitespace: true, message: '请输入密码' }]}
        >
          <Input.Password size="large" />
        </Form.Item>
        <Button
          size="large"
          htmlType="submit"
          className={styles.button}
          type="primary"
          block
        >
          登陆
        </Button>
      </Form>
    </div>
  );
};

export default LoginPage;
